﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dal;
using System.Xml;
using System.Diagnostics;
using System.Security.Cryptography;

namespace GpsAddIn2003
{
    public class CommOp
    {
        public void GetVehicleNowMap(string carCode)
        {
            try
            {
                string GpsMapKey = "";
                string uid = IniFile.ReadIniValue("Settings", "WebServersAccount", "", "Config.ini");
                string pwd = IniFile.ReadIniValue("Settings", "WebServersPwd", "", "Config.ini");
                System.Net.ServicePointManager.Expect100Continue = false;
                SrGps.ServiceSoapClient sg = new SrGps.ServiceSoapClient("ServiceSoap");
                #region 获取密钥
                XmlNode nodesvo = sg.GetVechileMapKey(uid, getPass(pwd), carCode);
                foreach (XmlNode node in nodesvo)
                {
                    if ("info".Equals(node.Name))
                    {
                        GpsMapKey = node.InnerText;
                    }
                }
                #endregion
                #region 依据密钥获取车辆当前位置图片
                Process.Start("http://s1.e6gps.com/E6WebGisServicesolog/MapServices/Orientation.aspx?sid=" + GpsMapKey);
                #endregion
            }
            catch
            {

            }
            
        }
        public void GetVehiclePlay(string carCode)
        {
            try
            {
                string GpsMapKey = "";
                string uid = IniFile.ReadIniValue("Settings", "WebServersAccount", "", "Config.ini");
                string pwd = IniFile.ReadIniValue("Settings", "WebServersPwd", "", "Config.ini");
                //System.Net.ServicePointManager.Expect100Continue = false;
                SrGps.ServiceSoapClient sg = new SrGps.ServiceSoapClient("ServiceSoap");
                //sg.BeginGetGPSVehicleAlarmByUser(uid, getPass(pwd), new AsyncCallback(MyGPSVehicleAlarm), sg);
                //sg.BeginGetVechileInfoByUser(uid, getPass(pwd), new AsyncCallback(MyVechileInfoByUser), sg);
                #region 获取密钥
                XmlNode nodesvo = sg.GetVechileMapKey(uid, getPass(pwd), carCode);
                foreach (XmlNode node in nodesvo)
                {
                    if ("info".Equals(node.Name))
                    {
                        GpsMapKey = node.InnerText;
                    }
                }
                #endregion
                #region 依据密钥获取车辆轨迹回放
                Process.Start("http://s1.e6gps.com/E6WebGisServices/MapServices/PlayTrack.aspx?sid=" + GpsMapKey);
                #endregion
            }
            catch
            {

            }
        }
        /// <summary>
        /// MD5加密
        /// </summary>
        public static string getPass(string str)
        {
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            byte[] encryptedBytes = md5.ComputeHash(Encoding.ASCII.GetBytes(str));
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < encryptedBytes.Length; i++)
            {
                sb.AppendFormat("{0:x2}", encryptedBytes[i]);
            }
            return sb.ToString().ToUpper();
        }
        public static void MyGPSVehicleAlarm(IAsyncResult iar)
        {
            try
            {

            }
            catch 
            {

            }
        }
        public static void MyVechileInfoByUser(IAsyncResult iar)
        {
            try
            {

            }
            catch
            {

            }
        }
    }
}
